#include "navigation.h"
#include "ui_navigation.h"
#include "global.h"

Navigation::Navigation(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Navigation)
{
    ui->setupUi(this);
}

Navigation::~Navigation()
{
    delete ui;
}

void Navigation::fnInitFormSlots(){
    isInitialization = true;
    ui->labIcon1->setFont(Global::IconFont);
    ui->labIcon1->setText(QChar(0xec8e));
    ui->labIcon2->setFont(Global::IconFont);
    ui->labIcon2->setText(QChar(0xec3e));
    ui->labIcon3->setFont(Global::IconFont);
    ui->labIcon3->setText(QChar(0xefb0));
    ui->labIcon4->setFont(Global::IconFont);
    ui->labIcon4->setText(QChar(0xef77));
    ui->labIcon5->setFont(Global::IconFont);
    ui->labIcon5->setText(QChar(0xef20));
    ui->labIcon6->setFont(Global::IconFont);
    ui->labIcon6->setText(QChar(0xeea2));
    ui->labIcon7->setFont(Global::IconFont);
    ui->labIcon7->setText(QChar(0xee2b));

    ui->labIcon4->setVisible(false);
    ui->CustomerService->setVisible(false);

    int fHeight = 28;
    QList<QPushButton *> lstButton = ui->frmWidget->findChildren<QPushButton *>();
    foreach (auto button, lstButton) {
        button->setFixedHeight(fHeight);
        connect(button, &QPushButton::clicked, this, [=](){
            QStringList param = {"OpenInsidePage", button->objectName()};
            emit MGlobal::fnGetInstance()->CallInsidePageAction(param);
            this->close();
        });
    }
    ui->widget->setFixedHeight(lstButton.size() * fHeight + ((lstButton.size()-1)*6));
    this->setFixedSize(150, ui->widget->height() + ui->label->height() + 9);
}

void Navigation::showEvent(QShowEvent*){
    if(!isInitialization)
        fnInitFormSlots();
}
